//
// Created by vista on 2017/12/11.
//

#ifndef P_P14_H
#define P_P14_H

#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
using namespace std;

class Solution {
public:

/*    vector<string> vector1;
    vector1.emplace_back("aa");
    vector1.emplace_back("a");
//    vector1.emplace_back("abede");

    std::cout << solution.longestCommonPrefix(vector1) << endl;*/

    string longestCommonPrefix(vector<string>& strs) {
        string s;
        if(strs.empty())
            return s;
        if(strs.size() == 1)
            return strs[0];
        s = strs[0];
        for (int j = 1; j < strs.size(); ++j) {
            auto size = static_cast<int>(strs[j].size());
            int nsize = std::min(size,(int)s.length());
            if(nsize < s.length()){
                s.erase(nsize);
            }
            for (int k = 0; k < nsize; ++k) {
                if(strs[j][k] != s[k]){
                    s.erase(static_cast<unsigned long>(k));
                    break;
                }
            }
        }
        return s;
    }
};
#endif //P_P14_H
